package com.esri.android.map.popup;

import android.app.Activity;
import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import com.esri.android.map.popup.ArcGISAttributesAdapter;
import com.esri.android.map.popup.ArcGISPopupStyle;
import com.esri.core.map.popup.PopupInfo;
import java.util.EnumSet;
import java.util.Set;

@Deprecated
/* loaded from: classes.dex */
public class ArcGISDescriptionAdapter extends ArcGISAttributesAdapter implements ArcGISPopupStyle.IPopupStylable {
    WebView a;
    String b;
    private boolean c;

    @Override // com.esri.android.map.popup.ArcGISAttributesAdapter
    protected ViewGroup createDefaultLayout(ArcGISAttributesAdapter.FIELD_TYPE field_type) {
        return null;
    }

    @Override // com.esri.android.map.popup.ArcGISAttributesAdapter, android.widget.Adapter
    public int getCount() {
        return 1;
    }

    @Override // com.esri.android.map.popup.ArcGISAttributesAdapter
    public void refresh() {
    }

    public ArcGISDescriptionAdapter(Context context, Popup popup) throws Exception {
        super(context, popup);
        this.c = false;
        if (context instanceof Activity) {
            ((Activity) context).runOnUiThread(new Runnable() { // from class: com.esri.android.map.popup.ArcGISDescriptionAdapter.1
                @Override // java.lang.Runnable
                public void run() {
                    ArcGISDescriptionAdapter.this.a = new WebView(ArcGISDescriptionAdapter.this.mContext);
                    PopupInfo popupInfo = ArcGISDescriptionAdapter.this.mPopup.a;
                    if (popupInfo != null) {
                        ArcGISDescriptionAdapter arcGISDescriptionAdapter = ArcGISDescriptionAdapter.this;
                        arcGISDescriptionAdapter.b = arcGISDescriptionAdapter.mValueFormat.a(ArcGISDescriptionAdapter.this.mFeatureType, popupInfo.getDescription());
                    }
                    ArcGISPopupStyle arcGISPopupStyle = (ArcGISPopupStyle) ArcGISDescriptionAdapter.this.mPopup.getLayout().getStyle();
                    arcGISPopupStyle.registerStylable(ArcGISDescriptionAdapter.this);
                    ArcGISDescriptionAdapter.this.applyStyle(arcGISPopupStyle, ArcGISPopupStyle.STYLE_ELEMENT.POPUP_BACKGROUND);
                    ArcGISDescriptionAdapter.this.applyStyle(arcGISPopupStyle, ArcGISPopupStyle.STYLE_ELEMENT.FIELD_VALUE);
                }
            });
            return;
        }
        throw new Exception("The WebView cannot be created");
    }

    @Override // android.widget.Adapter
    public View getView(int i, View view, final ViewGroup viewGroup) {
        WebView webView = this.a;
        if (webView == null) {
            return null;
        }
        if (!this.c) {
            webView.setOnTouchListener(new View.OnTouchListener() { // from class: com.esri.android.map.popup.ArcGISDescriptionAdapter.2
                @Override // android.view.View.OnTouchListener
                public boolean onTouch(View view2, MotionEvent motionEvent) {
                    viewGroup.onTouchEvent(MotionEvent.obtain(motionEvent));
                    if (motionEvent.getAction() != 2) {
                        return ArcGISDescriptionAdapter.this.a.onTouchEvent(motionEvent);
                    }
                    return false;
                }
            });
            this.c = true;
        }
        return this.a;
    }

    @Override // com.esri.android.map.popup.ArcGISPopupStyle.IPopupStylable
    public Set<ArcGISPopupStyle.STYLE_ELEMENT> getRegisteredStyle() {
        return EnumSet.of(ArcGISPopupStyle.STYLE_ELEMENT.POPUP_BACKGROUND, ArcGISPopupStyle.STYLE_ELEMENT.FIELD_VALUE);
    }

    @Override // com.esri.android.map.popup.ArcGISPopupStyle.IPopupStylable
    public void applyStyle(ArcGISPopupStyle arcGISPopupStyle, ArcGISPopupStyle.STYLE_ELEMENT style_element) {
        String str;
        if (ArcGISPopupStyle.STYLE_ELEMENT.POPUP_BACKGROUND.equals(style_element)) {
            this.a.setBackgroundColor(arcGISPopupStyle.getPopupBackgroundColor());
        } else if (!ArcGISPopupStyle.STYLE_ELEMENT.FIELD_VALUE.equals(style_element) || (str = this.b) == null || "".equals(str)) {
        } else {
            String format = String.format("#%06X", Integer.valueOf(arcGISPopupStyle.getFieldValueColor() & 16777215));
            this.a.loadDataWithBaseURL(null, "<font color='" + format + "'>" + this.b + "</font>", "text/html", "utf-8", null);
        }
    }
}
